package cn.bugstack.domain.strategy.model.entity;

import cn.bugstack.types.common.Constants;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.Collections;

/**
 * @Title: StrategyEntity
 * @Description:
 * @author: jiangta
 * @date: 2024/10/24 下午1:51
 * @Version: 1.0
 */
@Data
@Builder
public class StrategyEntity {

    /**
     * 抽奖策略ID
     */
    private Long strategyId;

    /**
     * 抽奖策略描述
     */
    private String strategyDesc;

    /**
     * 抽奖规则模型
     */
    private String ruleModels;

    public String[] ruleModels() {
        if(StringUtils.isBlank(ruleModels)) return null;
        return ruleModels.split(Constants.SPLIT);
    }

    public String getRuleWeight() {
        String[] ruleModes = this.ruleModels();
        if (ruleModes == null || ruleModes.length == 0) {
            return null;
        }
        for(String ruleModel : ruleModes) {
            if("rule_weight".equals(ruleModel)) return ruleModel;
        }
        return null;
    }
}